<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .demo {
            background-color: orange;
        }
    </style>
</head>

<body>
    <button>点我创建一个输入框</button>
    <script>
        const btn = document.querySelector('button');
        btn.onclick = () => {
            const input = document.createElement('input');

            input.className = 'demo';
            input.value = 100;


            document.body.appendChild(input);

            //有些操作必须要元素已经放入页面才生效，所以必须放在插入元素操作的后面

            input.focus();//这一步操作必须放在插入元素之后
            input.parentElement.style.backgroundColor = 'skyblue'
        }
    </script>
</body>

</html>